<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
//use Illuminate\Support\Facades\Schema;

class CreateHealthTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        if (!Schema::hasTable('health_body')) {
            Schema::create('health_body', function (Blueprint $table) {
                $table->id();
                $table->string('name')->comment('名称');
                $table->string('img')->comment('图片路径');
                $table->tinyInteger('status')->default(1)->comment('状态 1-正常 0-禁用');
                $table->timestamps();
                $table->comment = '身体分类表';
            });
        }

        if (!Schema::hasTable('health_meridian')) {
            Schema::create('health_meridian', function (Blueprint $table) {
                $table->id();
                $table->string('name')->comment('名称');
                $table->string('abbr_name')->comment('简称');
                $table->string('img')->comment('图片路径');
                $table->tinyInteger('status')->default(1)->comment('状态 1-正常 0-禁用');
                $table->timestamps();
                $table->comment = '经脉表';
            });
        }

        if (!Schema::hasTable('health_acupoint')) {
            Schema::create('health_acupoint', function (Blueprint $table) {
                $table->id();
                $table->string('name')->comment('名称');
                $table->longText('description')->comment('描述');
                $table->string('pin_yin')->comment('拼音');
                $table->string('point_description')->comment('位置描述');
                $table->string('img')->nullable()->comment('图片路径');
                $table->string('point_img')->nullable()->comment('位置图片路径');
                $table->string('video_file')->nullable()->comment('视频文件路径');
                $table->timestamps();
                $table->comment = '穴位表';
            });
        }

        if (!Schema::hasTable('health_body_part')) {
            Schema::create('health_body_part', function (Blueprint $table) {
                $table->id();
                $table->string('name')->comment('名称');
                $table->timestamps();
                $table->comment = '身体部位表';
            });
        }

        if (!Schema::hasTable('health_acu_body')) {
            Schema::create('health_acu_body', function (Blueprint $table) {
                $table->integer('acu_id')->comment('穴位id');
                $table->integer('body_id')->comment('身体分类id');
                $table->unique(['acu_id', 'body_id']);
                $table->comment = '穴位和身体分类关联表';
            });
        }

        if (!Schema::hasTable('health_acu_body_part')) {
            Schema::create('health_acu_body_part', function (Blueprint $table) {
                $table->integer('acu_id')->comment('穴位id');
                $table->integer('body_part_id')->comment('身体部位id');
                $table->unique(['acu_id', 'body_part_id']);
                $table->comment = '穴位和身体部位关联表';
            });
        }

        if (!Schema::hasTable('health_acu_meridian')) {
            Schema::create('health_acu_meridian', function (Blueprint $table) {
                $table->integer('acu_id')->comment('穴位id');
                $table->integer('meridian_id')->comment('经脉id');
                $table->unique(['acu_id', 'meridian_id']);
                $table->comment = '穴位和经脉关联表';
            });
        }

        if (!Schema::hasTable('health_disease_class')) {
            Schema::create('health_disease_class', function (Blueprint $table) {
                $table->id();
                $table->string('name')->comment('名称');
                $table->timestamps();
                $table->comment = '病症分类表';
            });
        }

        if (!Schema::hasTable('health_disease')) {
            Schema::create('health_disease', function (Blueprint $table) {
                $table->id();
                $table->integer('class_id')->unsigned()->index()->comment('分类id');
                $table->string('name')->comment('名称');
                $table->string('img')->comment('图片');
                $table->longText('introduce')->comment('介绍');
                $table->longText('treat_details')->nullable()->comment('调理详情');
                $table->longText('clinical_experience')->nullable()->comment('临床体会');
                $table->longText('case')->nullable()->comment('相关案例');
                $table->timestamps();
                $table->comment = '病症表';
            });
        }

        if (!Schema::hasTable('health_disease_scheme')) {
            Schema::create('health_disease_scheme', function (Blueprint $table) {
                $table->id();
                $table->integer('disease_id')->unsigned()->index()->comment('病症id');
                $table->integer('acu_id')->unsigned()->index()->comment('穴位id');
                $table->string('description')->comment('穴数');
                $table->integer('day')->comment('天数');
                $table->integer('time')->comment('时长 单位分钟');
                $table->timestamps();
                $table->comment = '病症调整方案表';
            });
        }

        if (!Schema::hasTable('health_breathe')) {
            Schema::create('health_breathe', function (Blueprint $table) {
                $table->id();
                $table->string('name')->comment('名称');
                $table->text('introduce')->comment('介绍');
                $table->string('img')->comment('图片');
                $table->integer('circle_num')->comment('循环次数');
                $table->integer('inhale_time')->comment('吸气时长 单位秒');
                $table->string('inhale_tip')->comment('吸气提示');
                $table->integer('exhale_time')->comment('呼气时长 单位秒');
                $table->string('exhale_tip')->comment('呼气提示');
                $table->integer('stay_time')->comment("屏气时长 单位秒");
                $table->tinyInteger('status')->default(1)->comment('状态 1-正常 0-禁用');
                $table->timestamps();
                $table->comment = '呼吸法表';
            });
        }

        if (!Schema::hasTable('health_plan')) {
            Schema::create('health_plan', function (Blueprint $table) {
                $table->id();
                $table->unsignedBigInteger('member_id')->index()->comment('会员ID');
                $table->string('mini_type', 50)->index()->comment('小程序类型');
                $table->unsignedInteger('disease_id')->index()->comment('病症ID');
                $table->string('acu_name')->comment('穴位名称');
                $table->integer('acu_num')->comment('穴位数量');
                $table->string('acu_img')->comment('穴位图片');
                $table->integer('finish_day')->default(0)->comment('完成天数');
                $table->integer('day')->comment('总天数');
                $table->tinyInteger('status')->default(0)->comment('状态 0-进行中 1-已完成');
                $table->integer('last_finish_time')->default(0)->comment('最后完成时间');
                $table->text('log')->nullable()->comment('完成记录');
                $table->timestamps();
                $table->comment = '我的计划';
            });
        }

        if (!Schema::hasTable('health_configs')) {
            Schema::create('health_configs', function (Blueprint $table) {
                $table->id();
                $table->string('name', 50)->default('')->comment('配置名');
                $table->string('group', 50)->default('')->comment('分组名');
                $table->text('value')->nullable()->comment('配置');
                $table->string('remark', 100)->default('')->comment('备注信息');
                $table->integer('sort')->default(0)->comment('排序');
                $table->timestamps();
                $table->unique(['group', 'name']);
                $table->comment = '穴位应用配置表';
            });
        }
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('health');
    }
}
